/***************************************************************************
 *   Copyright (C) 2009 by Marian Skvarek   *
 *   skvarek.marian@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A TrackICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "CPartVocalView.h"
#include "CPartVocal.h"

 #include "CScoreView.h"
 #include "CTrackView.h"

namespace easyscore
{
	namespace core
	{

//Constructors, Initialization & Destructors
		CPartVocalView::CPartVocalView ( CPartVocal * model )
		{
			mModel = model;
		}

		void CPartVocalView::initialize ()
		{
			CPartView::initialize();

			update();
		}

		void CPartVocalView::clear ()
		{
			CPartView::clear();
		}


		CPartVocalView::~CPartVocalView()
		{
			clear();
		}

//Public methods
		void CPartVocalView::update ()
		{
			CPartView::update();

			initializeTrackView ( mModel->getTrack() );
			getTrackView()->setPos ( 0,0 );

			refreshLayout();
		}

		void CPartVocalView::refreshLayout ()
		{
			CPartView::refreshLayout();

			int w = 0;
			if ( mModel->getTrack().hasView() )
				w = getTrackView()->rect().width();
			int h = 0;
			if ( mModel->getTrack().hasView() )
				h = getTrackView()->rect().height();



			setRect ( rect().x(), rect().y(), w, h );

			mScoreView->refreshLayout();
		}

//Protected methods
		CTrackView *CPartVocalView::getTrackView()
		{
			return mModel->getTrack().getView();
		}

		void CPartVocalView::initializeTrackView ( CTrack &track )
		{
			if ( !track.hasView() )
			{
				track.createView();
				track.getView()->setPartView ( this );
				track.getView()->initialize();
			}
		}

	}//namespace core
}//namespace easyscore
